var app = getApp();
Page({
  data: {
    titlrBar: [
    
    ],
    img_height: 1,
    option: '正在流行',
    menu: [
     
    ]
  },
  onLoad: function (options) {
    let that = this
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight
    })
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          img_height: res.windowHeight - app.globalData.navHeight,
        })
        console.info(that.data.img_height);
      }
    })
    
  },
  onReady: function () {
    var that = this;
    wx.request({
      url: app.globalData.url + "getParentProductTypeList",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result === 1) {
          that.setData({
            childProductType: data.data,
            option: data.data[0].typeName
          })
          console.info(that.data.childProductType);
          var parentTypeId = data.data[0].typeId;
          wx.request({
            url: app.globalData.url + "byParentTypeIdGetProductTypeList",
            header: {
              "content-type": "application/x-www-form-urlencoded"
            },
            data: {
              parentTypeId: parentTypeId
            },
            method: "POST",
            success: function (res) {
              var data = res.data;
              if (data.result === 1) {
                that.setData({
                  parentProductType: data.data
                })
              }
            }
          });
        }
      }
    });
  },
  clickTitle: function (e) {
    let that = this
          wx.request({
            url: app.globalData.url + "byParentTypeIdGetProductTypeList",
            header: {
              "content-type": "application/x-www-form-urlencoded"
            },
            data: {
              parentTypeId: e.currentTarget.dataset.ptypeid
            },
            method: "POST",
            success: function (res) {
              var data = res.data;
              if (data.result === 1) {
                that.setData({
                  parentProductType: data.data
                })
              }
              }
    });
    that.setData({
      option: e.currentTarget.dataset.title,
    })
  },
 find: function (e) {
    var that = this;
    console.log(e.detail.value)
    if (e.detail.value != ""){
      wx.request({
        url: app.globalData.url + "searchListByES",
        header: {
          "content-type": "application/x-www-form-urlencoded"
        },
        data: {
          searchCondition: e.detail.value,
          type: 2,
          parentTypeId: that.data.parentTypeId
        },
        method: "POST",
        success: function (res) {
          var data = res.data;
          if (data.result === 1) {
            that.setData({
              product: data.data,
            })
          }
        }
      });
    }else{
      that.productF(that.data.productTypeId);
    }
}, 
  navBack:function(){
    wx.navigateBack({
      
    })
  },
  goProductList: function (e) {
    wx.navigateTo({
      url: '/pages/productListNew/productListNew?typeId=' + e.currentTarget.dataset.parenttypeid
    })
  }
})